# @Time   : 2022-03-03 17:00:00
# @Author : Gavin Jiang
# @Owner  : YSRD (Insights Value)

import os
from abc import ABCMeta
from collections.abc import Iterable


class ThePath(metaclass=ABCMeta):

    @staticmethod
    def root():
        return os.path.dirname(os.path.dirname(os.path.dirname(__file__))).replace('\\', '/')

    @staticmethod
    def src():
        return os.path.join(ThePath.root(), 'src').replace('\\', '/')

    @staticmethod
    def test():
        return os.path.join(ThePath.root(), 'test').replace('\\', '/')

    @staticmethod
    def app():
        return os.path.join(ThePath.src(), 'app').replace('\\', '/')

    @staticmethod
    def bin():
        return os.path.join(ThePath.root(), 'bin').replace('\\', '/')

    @staticmethod
    def demo():
        return os.path.join(ThePath.root(), 'demo').replace('\\', '/')

    @staticmethod
    def config(path=None):
        config_path = os.path.join(ThePath.root(), 'config')
        if path:
            if isinstance(path, str):
                return os.path.join(config_path, path)
            elif isinstance(path, Iterable):
                for p in path:
                    config_path = os.path.join(config_path, p)
                return config_path

        return config_path.replace('\\', '/')

    @staticmethod
    def tmp(path=None):
        root = ThePath.root()

        tmp_path = os.path.join(root, 'tmp')
        if path:
            result = os.path.join(tmp_path, path)
        else:
            result = tmp_path

        if not os.path.exists(result):
            os.makedirs(result)

        return result.replace('\\', '/')

    @staticmethod
    def doc():
        return os.path.join(ThePath.root(), 'doc').replace('\\', '/')

    @staticmethod
    def font(name):
        return os.path.join(ThePath.root(), f'font/{name}').replace('\\', '/')
